package com.boot.multi.source.service.impl;

import com.boot.multi.source.domain.consumer.ConsumerUser;
import com.boot.multi.source.domain.producer.ProducerUser;
import com.boot.multi.source.mapper.consumer.ConsumerUserMapper;
import com.boot.multi.source.mapper.producer.ProducerUserMapper;
import com.boot.multi.source.service.ProducerAndConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 刘志强
 * @date 2020/11/27 14:35
 */
@Service
public class ProducerAndConsumerImpl implements ProducerAndConsumerService {

    @Autowired
    private ProducerUserMapper producerUserMapper;
    @Autowired
    private ConsumerUserMapper consumerUserMapper;

    @Override
    public Map<String, Object> getProducerUserAndConsumerUser(Long producerId, Long consumerId) {
        Map<String,Object> map = new HashMap<>(2);
        ProducerUser producerUser = producerUserMapper.getProducerUserById(producerId);
        map.put("producerUser",producerUser);
        ConsumerUser consumerUser = consumerUserMapper.getConsumerUserById(consumerId);
        map.put("consumerUser",consumerUser);
        return map;
    }

    @Override
    public String addProducerUserAndConsumerUser(String producerUserName, String consumerUserName) {
        ProducerUser producerUser = new ProducerUser();
        producerUser.setUserName(producerUserName);
        producerUserMapper.addProducerUser(producerUser);
        ConsumerUser consumerUser = new ConsumerUser();
        consumerUser.setUserName(consumerUserName);
        consumerUserMapper.addConsumerUser(consumerUser);
        return "添加成功";
    }
}
